#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# reception_tags.py
#
# Дополнительные теги сайта
#
# Copyright 2023 Elin K. V. <ip.elinkv@ya.ru>#
#
# Версия 1.0

from django import template
from reception.models import *

register = template.Library()


@register.simple_tag() #
def get_apps(filter=None):
    list_sm = External_systems.objects.filter(status=True, type_system=filter)
    if list_sm:
        return list_sm[0].content
    else:
        return  ' '


@register.simple_tag() #
def menu_var(filter=None, id_page=None):
    menu_page = Menu_page.objects.filter(status_point=True, type_page=filter)
    if menu_page:
        if menu_page[0].content:
            return menu_page[0].content
        else:
            list_menu = [f'''<li class="nav-item">
          <a class="nav-link" href="#{item.slug}">{item.title}</a>
        </li>''' for item in id_page]
            return str('<ul class="navbar-nav mr-auto mb-2 mb-lg-0">'+''.join(list_menu)+'</ul>')
    else:
        return 'Внесите меню в базу данных'


@register.simple_tag()
def main_data(filter=None):
    _main_dict = {}
    try:
        _main_data = Site_settings.objects.all()[0]
    except:
        _main_data = {}
    if _main_data:
        _main_dict = {'name_site': _main_data.name_site,
                      'descriptions': _main_data.descriptions,
                      'adress_text': _main_data.adress_text,
                      'main_telefon': _main_data.main_telefon,
                      'whatsapp_telefon': _main_data.whatsapp_telefon,
                      'telegram_link': _main_data.telegram_link,
                      'favicon': _main_data.favicon,
                      'logo': _main_data.logo,
                      'email_contact': _main_data.email_contact,
                      'header_color': _main_data.header_color,
                      'menu_color': _main_data.menu_color,
                      'menu_font_color': _main_data.menu_font_color,
                      'body_color': _main_data.body_color,
                      'footer_color': _main_data.footer_color,
                      }
    if _main_dict.get(filter):
        return _main_dict[filter]
    else:
        return ' '


@register.simple_tag()
def logo_url():
    _logo_ul = ' '
    try:
        _main_data = Site_settings.objects.all()[0]
        _logo_ul = _main_data.logo.url
    except:
        pass
    return _logo_ul


@register.simple_tag()
def favicon_url():
    _favicon_ul = ' '
    try:
        _main_data = Site_settings.objects.all()[0]
        _favicon_ul = _main_data.favicon.url
    except:
        pass
    return _favicon_ul
